package cn.jiyun.usain.controller;

import cn.jiyun.usain.pojo.Student;
import cn.jiyun.usain.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class HelloController {
    @Autowired
    private HelloService helloService;

    //查询
    @GetMapping("/findAll")
    public  String findAll(Model model){
         List<Student> students = helloService.findAll();
        model.addAttribute("student",students);
         return "show";

    }
    //添加
    @PostMapping("/add")
    public void add(@RequestBody Student student){
        helloService.add(student);
    }

    //根据id查询学生信息
    @GetMapping("/findById/{id}")
    public Student findById(@PathVariable("id") Integer id){
        Student student= helloService.findById(id);

        return student;
    }
    //修改
    @PostMapping("/update")
    public void update(@RequestBody Student student){
        helloService.update(student);
    }
    //删除
    @PostMapping("/delete/{id}")
    public void delete(@PathVariable("id") Integer id){
            helloService.delete(id);
    }



}
